// import cq from '@dfeidao/atom-nodejs/db/complex-query';
// import format from '@dfeidao/atom-nodejs/dt/format';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
// import { systemid } from '../../atom/config';

interface Message {
	filter: {
		productid: string;
		staff_no: string;
		type: string;
		page_no: number;
		page_size: number;
	};
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string[];
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:e:\feidao\yunfu\w000014\src\home\zj-000001\s005,action_id:' + action_id);

	// **暂时注销 */
	// const query = cq(action_id, session_id, systemid);
	// 消息接收者列表  获得消息id
	/* query.add_field('msg_receiver', 'msgid', 'msgid')
		.where_eq('msg_receiver', 'productid', message.filter.productid)
		.where_eq('msg_receiver', 'receiver_no', message.filter.staff_no);
	const res = await query.exec<{ msgid: string }>();
	const arr = Array();
	res.map((r) => {
		arr.push(r.msgid);
	}); */

	// type:"0"代表全部，“1”代表“工单”，“2”代表“任务”，“3”代表“消息”
	// 根据类型查询消息表
	// **暂时注销 */
	/* 	query.add_field('message', 'msg_cont', 'msg_cont')
			.add_field('message', 'msg_type_no', 'msg_type_no')
			.add_field('message', 'msg_type_name', 'msg_type_name')
			.add_field('message', 'serder_name', 'serder_name')
			.add_field('message', 'send_time', 'send_time')
			.add_field('message', 'msgtemplid', 'msgtemplid')
			.add_field('message', 'msgid', 'msgid')
			// todo .add_field('msg_page_params', 'param_no', 'param_no')
			// .add_field('msg_page_params', 'param_name', 'param_name')
			// .add_field('msg_type_page', 'msg_page_url', 'msg_page_url')
			// .add_field('msg_templ_page', 'package_path', 'package_path')
			// todo .outer_left_join('message', 'msg_page_params', ['msgid', 'msgid']) // 关联消息页面参数表msg_type_page
			.where_eq('message', 'productid', message.filter.productid)
			.where_in('message', 'msgid', arr)
			// .where_eq('msg_templ_page', 'productid', message.filter.productid)
			.where_in('message', 'msg_type_name', ['1', '2', '5', '10', '11'])
			// .where_in('message', 'msg_type_name', ['5'])
			.orderby_desc('send_time');
		const msg = await query.exec<{ send_time: string, msg_type_name: string }>(); */
	// **暂时注销 */
	/* msg.forEach((v) => {
		v.send_time = format(Number(v.send_time), 'YYYY-MM-DD');
	});

	const gd_msg = msg.filter((m) => {
		if (m.msg_type_name === '1') {
			return m;
		}
	});
	const rw_msg = msg.filter((m) => {
		if (m.msg_type_name === '2') {
			return m;
		}
	});
	const tz_msg = msg.filter((m) => {
		if (m.msg_type_name === '5') {
			return m;
		}
	});
	const kq_msg = msg.filter((m) => {
		if (m.msg_type_name === '10' || m.msg_type_name === '11') {
			return m;
		}
	}); */
	// **end */
	log('Service end path:e:\feidao\yunfu\w000014\src\home\zj-000001\s005,action_id:' + action_id);
	return { data: { gd_msg: undefined, rw_msg: undefined, tz_msg: undefined, kq_msg: undefined } } as IWebResult;
}
